package com.ewayde.base.statemachine.impl;

import com.ewayde.base.statemachine.State;
import com.ewayde.base.statemachine.Transition;

import java.util.List;

/**
 * @author yanwei li create  2024-05-28 22:24
 */
public class StateImpl<S,E,C> implements State<S,E,C> {

    protected final S stateId;

    public StateImpl(S stateId) {
        this.stateId = stateId;
    }

    private EventTransitions eventTransitions = new EventTransitions();



    /**
     * 获取状态
     */
    @Override
    public S getId() {
        return this.stateId;
    }

    @Override
    public Transition<S, E, C> addTransition(E event, State<S, E, C> target) {

        Transition<S,E,C> transition = new TransitionImpl<>();
        transition.setSourceState(this);
        transition.setTargetState(target);
        transition.setEvent(event);
        eventTransitions.put(event,transition);
        return transition;
    }

    @Override
    public List<Transition<S, E, C>> getEventTransitions(E event) {
        return eventTransitions.getEventTransition(event);
    }
}
